import java.util.*;

public class Leet454 {
    public static void main(String[] args) {
        Leet454 l = new Leet454();
        System.out.println(l.fourSumCount(new int[]{0,1},new int[]{-1,1},new int[]{0,0},new int[]{-1,1}));
    }
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Arrays.sort(nums4);
        int len = nums1.length;
        int num = 0;
        Map<Integer,Integer> map = new HashMap<>();
        Map<Integer,Integer> map1 = new HashMap<>();
        int te1,te2;
        for (int i = 0; i < len; i++) {
            for (int i1 = 0; i1 < len; i1++) {
                te1 = nums1[i]+nums2[i1];
                te2 = nums3[i]+nums4[i1];
                if (map.containsKey(te1))
                    map.put(te1,map.get(te1)+1);
                else map.put(te1,1);
                if (map1.containsKey(te2))
                    map1.put(te2,map1.get(te2)+1);
                else map1.put(te2,1);
            }
        }
        for (Integer integer : map.keySet()) {
            if (map1.containsKey(-integer)){
                num+=map.get(integer)*map1.get(-integer);
            }
        }
        return num;
    }
}
